package com.fulu.game.bi;

import cn.hutool.core.collection.CollectionUtil;
import com.fulu.game.bi.common.util.lang.StringUtils;

import java.util.Collection;
import java.util.Objects;
import java.util.function.Supplier;

public class AssertHelper {

    public static void assertNull(Object obj, Supplier<? extends RuntimeException> exceptionSupplier) {
        assertTrue(Objects.isNull(obj), exceptionSupplier);
    }

    public static void assertNotNull(Object obj, Supplier<? extends RuntimeException> exceptionSupplier) {
        assertTrue(Objects.nonNull(obj), exceptionSupplier);
    }

    public static void assertEmpty(String str, Supplier<? extends RuntimeException> exceptionSupplier) {
        assertTrue(StringUtils.isEmpty(str), exceptionSupplier);
    }

    public static void assertEmpty(Collection collection, Supplier<? extends RuntimeException> exceptionSupplier) {
        assertTrue(CollectionUtil.isEmpty(collection), exceptionSupplier);
    }

    public static void assertNotEmpty(String str, Supplier<? extends RuntimeException> exceptionSupplier) {
        assertTrue(StringUtils.isNotEmpty(str), exceptionSupplier);
    }

    public static void assertNotEmpty(Collection collection, Supplier<? extends RuntimeException> exceptionSupplier) {
        assertTrue(CollectionUtil.isNotEmpty(collection), exceptionSupplier);
    }


    public static void assertFalse(boolean status, Supplier<? extends RuntimeException> exceptionSupplier) {
        assertTrue(!status, exceptionSupplier);
    }

    public static void assertTrue(boolean status, Supplier<? extends RuntimeException> exceptionSupplier) {
        if (!status) {
            throw exceptionSupplier.get();
        }
    }
}
